import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
      title: 'Flutter教程04-2',
      // home: ListDemo(
      //   items: List<String>.generate(1000, (i) => "Item $i"),
      // ),
  home: GridViewDemo(),
    ));

class ListDemo extends StatelessWidget {
  final List<String> items;

  ListDemo({this.items});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('ListDemo'),
      ),
      body: ListView.builder(
          itemCount: items.length,
          itemBuilder: (context, index) {
            return ListTile(
              title: Text('${items[index]}'),
            );
          }),
    );
  }
}

class GridViewDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('GridViewDemo'),
      ),
      body: GridView.count(crossAxisCount: 2,
        crossAxisSpacing: 100.0,
        scrollDirection: Axis.vertical,
        children: <Widget>[
          Image.asset('images/yueliang.png'),
          Image.asset('images/yueliang.png'),
          Image.asset('images/yueliang.png'),
          Image.asset('images/yueliang.png'),
          Image.asset('images/yueliang.png'),
          Image.asset('images/yueliang.png'),
          Image.asset('images/yueliang.png'),
          Image.asset('images/yueliang.png'),
          Image.asset('images/yueliang.png'),
        ],
      ),
    );
  }
}

